package com.demostic.demostic_test.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.View;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.PayloadCallback;
import com.accloud.cloudservice.VoidCallback;
import com.accloud.service.ACClassDataMgr;
import com.accloud.service.ACDeviceMsg;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;
import com.accloud.service.ACObject;
import com.accloud.utils.LogUtil;
import com.badoo.mobile.util.WeakHandler;
import com.demostic.demostic_test.R;
import com.demostic.demostic_test.activity.MapActivity_901;
import com.demostic.demostic_test.entity.ForbiddenInfo;
import com.demostic.demostic_test.entity.GetMapidMap;
import com.demostic.demostic_test.entity.RealTimeMapInfo;
import com.demostic.demostic_test.entity.RoomNameInfo;
import com.demostic.demostic_test.entity.TimeAreaInfo;
import com.demostic.demostic_test.entity.VirTualInfo;
import com.demostic.demostic_test.utils.DataUtils;
import com.demostic.demostic_test.utils.DeviceUtils;
import com.demostic.demostic_test.utils.DisplayUtil;
import com.demostic.demostic_test.utils.MyLog;
import com.demostic.demostic_test.utils.OderByTime;
import com.glidebitmappool.GlideBitmapPool;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpClient;

import org.greenrobot.eventbus.EventBus;
import org.java_websocket.drafts.Draft_75;
import org.json.JSONException;
import org.json.JSONObject;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

public class MapView901 extends View implements View.OnTouchListener {
    public static final int DRAG = 2;
    public static final int NONE = 1;
    private static final int START_AUTO_SCALE = 1;
    public static final int ZOOM = 3;
    public static HashMap<Integer, Paint> drawHm;
    public static HashMap<Integer, Paint> hm;
    public static HashMap<Integer, Paint> hms;
    public static HashMap<Integer, RoomNameInfo> nameList;
    public static HashMap<Integer, Paint> realDrawHm;
    public static int space = 6;
    private int MOPFBD = 1;
    private int OVAFBD = 0;
    private final String TAG = MapView901.class.getSimpleName();
    private int WHGFBD = 2;
    private Bitmap bitmap_mapid;
    private Bitmap bitmap_slam;
    private Bitmap bt;
    private byte[] bytes_subscribe;
    private Canvas canvas_mapid;
    private Canvas canvas_slam;
    private Rect chRect;
    private Bitmap chb_bitmap;
    private int cleanArea;
    private Context context;
    private float curScale = 1.0f;
    private Paint cvPaint;
    private ACClassDataMgr.ClassDataReceiver dataReceiver;
    private long deviceId;
    private float distance;
    private Paint drBitPaint;
    private float drgx;
    private float drgy;
    private float dx;
    private float dy;
    private ArrayList<ForbiddenInfo> fbdInfoList;
    private Path fbdPath;
    private Paint.FontMetrics fontMetrics;
    private WeakHandler handler = new WeakHandler(new Handler.Callback() {
        /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass1 */

        @Override // android.os.Handler.Callback
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    MapView901.this.isAutoScale = true;
                    MapView901.this.drgx = 0.0f;
                    MapView901.this.drgy = 0.0f;
                    return false;
                default:
                    return false;
            }
        }
    });
    private int height;
    private TimeAreaInfo info;
    private boolean isAutoScale;
    private boolean isFirst;
    private boolean isFirsts;
    private Canvas mCanvas;
    private WeakHandler mHandler;
    private byte[] mapidBytes;
    private int mapid_xmax;
    private int mapid_xmin;
    private int mapid_ymax;
    private int mapid_ymin;
    private Matrix matrix = new Matrix();
    private Matrix matrixs = new Matrix();
    private float maxScale = 5.0f;
    PointF midPoint;
    private float minScale = 0.5f;
    int mode = 0;
    private float orgScale = 1.0f;
    float oriDis = 1.0f;
    private ArrayList<ArrayList<Integer>> packageLists;
    private int pageNo = 1;
    private Paint paint_1;
    private Paint paint_2;
    private Paint paint_mopfbd;
    private Paint paint_ovafbd;
    private Paint paint_position;
    private Paint paint_road;
    private Paint paint_slam;
    private Paint paint_stroke;
    private Paint paint_virtual;
    private Paint paint_whg;
    private String physicalDeviceId;
    private Paint pt_oval;
    private Paint pt_text;
    private int real_xmax;
    private int real_xmin;
    private int real_ymax;
    private int real_ymin;
    private RectF rectF;
    private PointF rectMid;
    private ArrayList<ArrayList<Integer>> roadPoints;
    private byte[] slamBytes;
    PointF startPoint;
    private String subdomain;
    private int svHeight;
    private int svWidth;
    private TimerTask task;
    private Rect textRect;
    private Timer timer;
    private ArrayList<VirTualInfo> vtInfoList;
    private ArrayList<ForbiddenInfo> whgInfoList;
    private int width;
    private int workTime;
    int x = 0;
    int y = 0;

    static /* synthetic */ int access$1808(MapView901 x0) {
        int i = x0.pageNo;
        x0.pageNo = i + 1;
        return i;
    }

    public MapView901(Context context2, long deviceId2, String physicalDeviceId2, String subdomain2, WeakHandler handler2) {
        super(context2);
        this.context = context2;
        this.deviceId = deviceId2;
        this.physicalDeviceId = physicalDeviceId2;
        this.subdomain = subdomain2;
        this.mHandler = handler2;
        init();
        initBitMap();
        initPaint();
        initDataReceiver();
        initTimer();
        subscribeRealTimeMap();
        subscribeVirFbd();
        subscribeCleanArea();
        subscribeMapIDChange();
        setOnTouchListener(this);
    }

    public void initTimer() {
        this.timer = new Timer();
        this.task = new TimerTask() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass2 */

            @Override // java.util.TimerTask, java.lang.Runnable
            public void run() {
                MyLog.e(MapView901.this.TAG, "getRealTimeMap timer===:" + MapActivity_901.isPauseGetSlam);
                if (!MapActivity_901.isPauseGetSlam) {
                    MapView901.this.getRealTimeMap();
                }
            }
        };
        this.timer.schedule(this.task, 0, 3000);
    }

    private void init() {
        this.slamBytes = null;
        this.mapidBytes = null;
        this.isFirst = true;
        this.isFirsts = true;
        this.isAutoScale = true;
        this.info = new TimeAreaInfo();
        this.fbdPath = new Path();
        this.rectMid = new PointF();
        this.startPoint = new PointF();
        this.rectF = new RectF();
        this.packageLists = new ArrayList<>();
        this.roadPoints = new ArrayList<>();
        this.vtInfoList = new ArrayList<>();
        this.whgInfoList = new ArrayList<>();
        this.fbdInfoList = new ArrayList<>();
        nameList = new HashMap<>();
        this.drBitPaint = new Paint();
        this.drBitPaint.setFilterBitmap(false);
        this.drBitPaint.setAntiAlias(false);
        this.chb_bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.charge_base);
        this.chRect = new Rect(0, 0, this.chb_bitmap.getWidth(), this.chb_bitmap.getHeight());
    }

    private void initBitMap() {
        try {
            this.bitmap_slam = GlideBitmapPool.getBitmap(AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError error) {
            MyLog.e(this.TAG, "initBitMap error bitmap_slam:" + error.toString());
        }
        try {
            this.bitmap_mapid = GlideBitmapPool.getBitmap(AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, AsyncHttpClient.DEFAULT_RETRY_SLEEP_TIME_MILLIS, Bitmap.Config.ARGB_8888);
        } catch (OutOfMemoryError error2) {
            MyLog.e(this.TAG, "initBitMap error bitmap_mapid:" + error2.toString());
        }
        this.canvas_slam = new Canvas(this.bitmap_slam);
        this.canvas_mapid = new Canvas(this.bitmap_mapid);
    }

    private void initPaint() {
        this.cvPaint = DisplayUtil.getMapPaint(getResources().getColor(R.color.paint_f2));
        this.paint_road = DisplayUtil.getRoadPaint(getResources().getColor(R.color.road_color));
        this.paint_position = DisplayUtil.getHostPaint(getResources().getColor(R.color.position_color));
        this.paint_virtual = DisplayUtil.getRoadPaint(getResources().getColor(R.color.color_vir));
        this.paint_virtual.setStrokeWidth(1.0f);
        this.paint_ovafbd = DisplayUtil.getFbdPaint();
        this.paint_mopfbd = DisplayUtil.getFbdPaints();
        this.paint_whg = DisplayUtil.getWhgPaint();
        this.paint_stroke = DisplayUtil.getRoadPaint(getResources().getColor(R.color.color_vir));
        this.paint_stroke.setStrokeWidth(1.0f);
        this.paint_slam = new Paint();
        this.paint_1 = DisplayUtil.getMapPaint(getResources().getColor(R.color.obstacles_color));
        this.paint_2 = DisplayUtil.getMapPaint(getResources().getColor(R.color.notclean_color));
        drawHm = DisplayUtil.getdrPainthm(this.context);
        realDrawHm = DisplayUtil.getdrPainthm(this.context);
        hm = DisplayUtil.getdrPainthm(this.context);
        hms = DisplayUtil.getPainthms(this.context);
        this.pt_oval = DisplayUtil.getMapPaint(getResources().getColor(R.color.pa_oval));
        this.pt_oval.setStyle(Paint.Style.FILL);
        this.pt_oval.setAntiAlias(true);
        this.pt_text = DisplayUtil.getMapPaint(-1);
        this.pt_text.setTextSize(10.0f);
        this.pt_text.setAntiAlias(true);
        this.pt_text.setTextAlign(Paint.Align.CENTER);
        this.fontMetrics = this.pt_text.getFontMetrics();
        this.distance = ((this.fontMetrics.bottom - this.fontMetrics.top) / 2.0f) - this.fontMetrics.bottom;
        this.textRect = new Rect();
    }

    private void setpicMatrixs(float curScale2) {
        float sx = 1.0f / curScale2;
        if (sx > 0.3f) {
            sx = 0.3f;
        }
        if (sx < 0.1f) {
            sx = 0.1f;
        }
        this.matrixs.reset();
        this.matrixs.postScale(sx, sx);
        this.bt = Bitmap.createBitmap(this.chb_bitmap, 0, 0, this.chb_bitmap.getWidth(), this.chb_bitmap.getHeight(), this.matrixs, true);
        this.paint_road.setStrokeWidth(2.0f / curScale2);
    }

    /* access modifiers changed from: protected */
    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        this.mCanvas = canvas;
        if (this.width == 0 || this.height == 0) {
            this.width = getMeasuredWidth();
            this.height = getMeasuredHeight();
        }
        canvas.drawColor(0, PorterDuff.Mode.CLEAR);
        if (!(this.mode == 2 || this.mode == 3)) {
            this.canvas_slam.drawColor(0, PorterDuff.Mode.CLEAR);
            this.canvas_mapid.drawColor(0, PorterDuff.Mode.CLEAR);
        }
        canvas.drawPaint(this.cvPaint);
        this.matrix.reset();
        if (this.svWidth == 0 || this.svHeight == 0) {
            this.matrix.postTranslate((((float) (this.width / 2)) - this.rectMid.x) + this.drgx, (((float) (this.height / 2)) - this.rectMid.y) + this.drgy);
            this.matrix.postScale(this.curScale, this.curScale, (float) (this.width / 2), (float) (this.height / 2));
        } else {
            this.matrix.postTranslate((((float) (this.svWidth / 2)) - this.rectMid.x) + this.drgx, (((float) (this.svHeight / 2)) - this.rectMid.y) + this.drgy);
            this.matrix.postScale(this.curScale, this.curScale, (float) (this.svWidth / 2), (float) (this.svHeight / 2));
        }
        MyLog.e(this.TAG, "test scale map ondraw 画布偏移量:" + this.svWidth + "," + this.svHeight + "," + this.width + "," + this.height + "," + this.rectMid.x + "," + this.rectMid.y);
        canvas.concat(this.matrix);
        setpicMatrixs(this.curScale);
        drawMap();
        if (nameList != null && nameList.size() > 0) {
            for (Map.Entry<Integer, RoomNameInfo> entry : nameList.entrySet()) {
                RoomNameInfo info2 = entry.getValue();
                String roomname = info2.getRoomname();
                if (!roomname.equals("")) {
                    int[] namecoord = info2.getNamecoordinate();
                    int x2 = namecoord[0];
                    int y2 = 1500 - namecoord[1];
                    this.pt_text.getTextBounds(roomname, 0, roomname.length(), this.textRect);
                    this.rectF.set((float) ((x2 - (this.textRect.width() / 2)) - 5), (float) ((y2 - (this.textRect.height() / 2)) - 5), (float) ((this.textRect.width() / 2) + x2 + 5), (float) ((this.textRect.height() / 2) + y2 + 5));
                    float baseline = this.rectF.centerY() + this.distance;
                    canvas.drawRoundRect(this.rectF, 50.0f, 50.0f, this.pt_oval);
                    canvas.drawText(roomname, this.rectF.centerX(), baseline, this.pt_text);
                }
            }
        }
        if (this.vtInfoList.size() > 0) {
            int size = this.vtInfoList.size();
            for (int i = 0; i < size; i++) {
                VirTualInfo info3 = this.vtInfoList.get(i);
                if (info3.getEnable() == 1) {
                    int[] virData = info3.getVirData();
                    canvas.drawLine((float) virData[0], (float) virData[1], (float) virData[2], (float) virData[3], this.paint_virtual);
                }
            }
        }
        if (this.fbdInfoList.size() > 0) {
            int fbsize = this.fbdInfoList.size();
            for (int i2 = 0; i2 < fbsize; i2++) {
                ForbiddenInfo info4 = this.fbdInfoList.get(i2);
                if (info4.getEnable() == 1) {
                    int[] fbdData = info4.getFbdData();
                    drawUnifyFbdPath(fbdData[0], fbdData[1], fbdData[2], fbdData[3], fbdData[4], fbdData[5], fbdData[6], fbdData[7], info4.getFbdType());
                }
            }
        }
    }

    private void drawMap() {
        if (this.mode == 2 || this.mode == 3) {
            this.mCanvas.drawBitmap(this.bitmap_slam, 0.0f, 0.0f, this.drBitPaint);
            this.mCanvas.drawBitmap(this.bitmap_mapid, 0.0f, 0.0f, this.drBitPaint);
        } else {
            drawMapByBytes(this.slamBytes, this.canvas_slam, this.bitmap_slam);
            drawMapByBytes(this.mapidBytes, this.canvas_mapid, this.bitmap_mapid);
        }
        if (this.whgInfoList.size() > 0) {
            int fbsize = this.whgInfoList.size();
            for (int i = 0; i < fbsize; i++) {
                ForbiddenInfo info2 = this.whgInfoList.get(i);
                int[] fbdData = info2.getFbdData();
                drawUnifyFbdPath(fbdData[0], fbdData[1], fbdData[2], fbdData[3], fbdData[4], fbdData[5], fbdData[6], fbdData[7], info2.getFbdType());
            }
        }
        drawMapRoad();
        if (!(MapActivity_901.chPoint.x == 0 || MapActivity_901.chPoint.y == 0)) {
            this.mCanvas.drawBitmap(this.chb_bitmap, this.chRect, getDstRects(MapActivity_901.chPoint.x, MapActivity_901.chPoint.y), (Paint) null);
        }
        if (this.roadPoints.size() == 0 && this.packageLists.size() == 0 && MapActivity_901.hsPoint.x != 0 && MapActivity_901.hsPoint.y != 0) {
            this.mCanvas.drawCircle((float) MapActivity_901.hsPoint.x, (float) MapActivity_901.hsPoint.y, 15.0f / this.curScale, this.paint_position);
        }
        this.mCanvas.save();
    }

    private void drawMapByBytes(byte[] bytes, Canvas canvas, Bitmap bitmap) {
        if (bytes != null) {
            int btlength = bytes.length;
            for (int i = 0; i < btlength; i += 3) {
                int attr = bytes[i] & Draft_75.END_OF_FRAME;
                int length = DataUtils.bytesToUInt(new byte[]{bytes[i + 1], bytes[i + 2]}, 0);
                if (attr == 1) {
                    this.paint_slam = this.paint_1;
                } else if (attr == 2 || attr == 11) {
                    this.paint_slam = drawHm.get(1);
                } else if (attr > 11) {
                    this.paint_slam = drawHm.get(Integer.valueOf(attr - 10));
                }
                for (int j = 0; j < length; j++) {
                    if (this.x >= 1500) {
                        this.x = 0;
                        this.y++;
                    }
                    if (attr != 3) {
                        canvas.drawPoint((float) this.x, (float) (1500 - this.y), this.paint_slam);
                        LogUtil.d("x-->" + (float) this.x + ",y-->" + (float) (1500 - this.y));
                    }
                    this.x++;
                }
            }
            this.x = 0;
            this.y = 0;
            this.mCanvas.drawBitmap(bitmap, 0.0f, 0.0f, this.drBitPaint);
        }
    }

    private void drawMapRoad() {
        drawRoads(this.roadPoints, 1);
        drawRoads(this.packageLists, 2);
    }

    private void drawRoads(ArrayList<ArrayList<Integer>> roadp, int tag) {
        int size = roadp.size();
        if (size > 0) {
            Iterator<ArrayList<Integer>> it = roadp.iterator();
            while (it.hasNext()) {
                ArrayList<Integer> integers = it.next();
                int itsize = integers.size();
                for (int j = 0; j < itsize - 2; j += 2) {
                    if ((Math.abs(integers.get(j).intValue()) <= 1500 || Math.abs(1500 - integers.get(j + 1).intValue()) <= 1500) && (Math.abs(integers.get(j + 2).intValue()) <= 1500 || Math.abs(1500 - integers.get(j + 3).intValue()) <= 1500)) {
                        this.mCanvas.drawLine((float) integers.get(j).intValue(), 1500.0f - ((float) integers.get(j + 1).intValue()), (float) integers.get(j + 2).intValue(), 1500.0f - ((float) integers.get(j + 3).intValue()), this.paint_road);
                    }
                }
            }
            if (tag != 1) {
                drawPosition(roadp.get(size - 1));
            } else if (this.isFirsts) {
                drawPosition(roadp.get(size - 1));
            }
        }
    }

    private void drawPosition(ArrayList<Integer> integers) {
        this.mCanvas.drawCircle((float) integers.get(integers.size() - 2).intValue(), (float) (1500 - integers.get(integers.size() - 1).intValue()), 10.0f / this.curScale, this.paint_position);
        this.mCanvas.save();
    }

    @Override // android.view.View.OnTouchListener
    public boolean onTouch(View view, MotionEvent event) {
        switch (event.getAction() & 255) {
            case 0:
                initDraging(event);
                this.isAutoScale = false;
                this.handler.removeMessages(1);
                break;
            case 1:
                this.handler.sendEmptyMessageDelayed(1, 15000);
                invalidate();
                this.dx = this.drgx;
                this.dy = this.drgy;
                this.mode = 1;
                break;
            case 2:
                doDragOrZoom(event);
                break;
            case 5:
                initZooming(event);
                break;
            case 6:
                this.orgScale = this.curScale;
                break;
        }
        return true;
    }

    private void drawUnifyFbdPath(int start_x, int start_y, int sx, int my, int move_x, int move_y, int mx, int sy, int fbdtype) {
        this.fbdPath = DataUtils.getPath(this.fbdPath, new int[]{start_x, start_y, sx, my, move_x, move_y, mx, sy});
        float[] floats = {(float) start_x, (float) start_y, (float) sx, (float) my, (float) sx, (float) my, (float) move_x, (float) move_y, (float) move_x, (float) move_y, (float) mx, (float) sy, (float) mx, (float) sy, (float) start_x, (float) start_y};
        if (fbdtype == this.OVAFBD) {
            this.mCanvas.drawPath(this.fbdPath, this.paint_ovafbd);
            this.mCanvas.drawLines(floats, this.paint_stroke);
        } else if (fbdtype == this.MOPFBD) {
            this.mCanvas.drawPath(this.fbdPath, this.paint_mopfbd);
            this.mCanvas.drawLines(floats, this.paint_mopfbd);
        } else if (fbdtype == this.WHGFBD) {
            this.mCanvas.drawPath(this.fbdPath, this.paint_whg);
            this.mCanvas.drawLines(floats, this.paint_whg);
        }
    }

    private Rect getDstRects(int x2, int y2) {
        return new Rect(x2 - (this.bt.getWidth() / 2), y2 - (this.bt.getHeight() / 2), (this.bt.getWidth() / 2) + x2, (this.bt.getHeight() / 2) + y2);
    }

    private void initDraging(MotionEvent event) {
        this.startPoint.set(event.getX(), event.getY());
        this.mode = 2;
    }

    private void initZooming(MotionEvent event) {
        this.oriDis = DataUtils.distance(event);
        if (this.oriDis > 10.0f) {
            this.midPoint = DataUtils.midPoint(event);
            this.mode = 3;
        }
    }

    private void doDragOrZoom(MotionEvent event) {
        if (this.mode == 2) {
            this.drgx = ((event.getX() - this.startPoint.x) / this.curScale) + this.dx;
            this.drgy = ((event.getY() - this.startPoint.y) / this.curScale) + this.dy;
            invalidate();
        } else if (this.mode == 3) {
            float newDist = DataUtils.distance(event);
            if (newDist > 10.0f) {
                this.curScale = (newDist / this.oriDis) * this.orgScale;
                if (this.curScale >= 10.0f) {
                    this.curScale = 10.0f;
                }
                if (this.curScale <= this.minScale) {
                    this.curScale = this.minScale;
                }
                invalidate();
            }
        }
    }

    private void subscribeRealTimeMap() {
        subscribeData("clean_realtime");
    }

    private void subscribeVirFbd() {
        subscribeData("forbid_area_setting");
    }

    private void subscribeCleanArea() {
        subscribeData("clean_area_info");
    }

    private void subscribeMapIDChange() {
        subscribeData("robot_map_id");
    }

    private void subscribeData(String str) {
        Map<String, Object> primaryKey = new HashMap<>();
        primaryKey.put("device_id", Long.valueOf(this.deviceId));
        AC.classDataMgr().subscribe(str, primaryKey, 15, new VoidCallback() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass3 */

            @Override // com.accloud.cloudservice.VoidCallback
            public void success() {
                AC.classDataMgr().registerDataReceiver(MapView901.this.dataReceiver);
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapView901.this.TAG, "subscribeData error " + e.toString());
            }
        });
    }

    private void initDataReceiver() {
        this.dataReceiver = new ACClassDataMgr.ClassDataReceiver() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass4 */

            @Override // com.accloud.service.ACClassDataMgr.ClassDataReceiver
            public void onReceive(String s, int i, String s1) {
                MyLog.e(MapView901.this.TAG, "initDataReceiver onReceive:" + s1);
                try {
                    JSONObject jsonObject = new JSONObject(s1);
                    if (jsonObject.has("clean_data")) {
                        MapView901.this.getRealTimeData(s1);
                    }
                    if (jsonObject.has("forbid_area_setting")) {
                        MapView901.this.getVirFbdData(s1);
                    }
                    if (jsonObject.has("clean_area")) {
                        MapView901.this.getCleanAreaData(s1);
                    }
                    if (jsonObject.has("map_id")) {
                        MapView901.this.getMapByMapID(s1);
                    }
                } catch (JSONException e) {
                    MyLog.e(MapView901.this.TAG, "JSONException e = " + e.toString());
                    e.printStackTrace();
                }
            }
        };
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getMapByMapID(String s1) {
        MyLog.e(this.TAG, "get onReceive data robot_map_id:" + s1);
        EventBus.getDefault().post(new GetMapidMap(s1));
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRealTimeData(String s1) {
        boolean z;
        MyLog.e(this.TAG, "get onReceive data clean_realtime:" + s1);
        synchronized (this) {
            RealTimeMapInfo mapInfo = (RealTimeMapInfo) new Gson().fromJson(s1, RealTimeMapInfo.class);
            if (this.canvas_slam != null) {
                if (mapInfo.getPackage_num() == 1) {
                    this.bytes_subscribe = Base64.decode(mapInfo.getClean_data(), 0);
                }
                if (this.bytes_subscribe[0] == 2) {
                    ArrayList<Integer> realpoints = new ArrayList<>();
                    this.info.setQuery(false);
                    int length = this.bytes_subscribe.length;
                    for (int j = 2; j <= length - 4; j += 4) {
                        int x2 = DataUtils.bytesToInt(new byte[]{this.bytes_subscribe[j], this.bytes_subscribe[j + 1]}, 0);
                        int y2 = DataUtils.bytesToInt(new byte[]{this.bytes_subscribe[j + 2], this.bytes_subscribe[j + 3]}, 0);
                        if ((y2 == 32767) && (x2 == 32767)) {
                            MyLog.e(this.TAG, "test clear map:" + x2 + "<->" + y2);
                            this.workTime = 0;
                            this.cleanArea = 0;
                            clearRealSlam();
                            this.info.setQuery(true);
                        } else {
                            realpoints.add(Integer.valueOf(((x2 * 224) / 100) + 750));
                            realpoints.add(Integer.valueOf(((y2 * 224) / 100) + 750));
                        }
                    }
                    if (realpoints.size() > 0) {
                        this.packageLists.add(realpoints);
                    }
                }
                invalidate();
                this.isFirsts = false;
                this.workTime = mapInfo.getReal_clean_time();
                this.cleanArea = mapInfo.getReal_clean_area();
                this.info.setArea(this.cleanArea);
                this.info.setTime(this.workTime);
                EventBus.getDefault().post(this.info);
                MyLog.e(this.TAG, "test map road data getEvent subcrib==:" + this.cleanArea + "<->" + this.workTime + "<->" + this.packageLists.size());
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getVirFbdData(String s1) {
        byte[] decode;
        MyLog.e(this.TAG, "get onReceive data forbid_area_setting:" + s1);
        try {
            String st = new JSONObject(s1).getString("forbid_area_setting");
            if (!TextUtils.isEmpty(st) && (decode = Base64.decode(st, 0)) != null && decode.length > 0) {
                this.vtInfoList.clear();
                this.fbdInfoList.clear();
                ArrayList<VirTualInfo> virTualInfos = DataUtils.decodeVirData(decode, false);
                if (virTualInfos.size() > 0) {
                    this.vtInfoList.addAll(virTualInfos);
                }
                ArrayList<ForbiddenInfo> forbiddenInfos = DataUtils.decodeFbdData(decode, false);
                if (forbiddenInfos.size() > 0) {
                    this.fbdInfoList.addAll(forbiddenInfos);
                }
                invalidate();
            }
        } catch (JSONException e) {
            MyLog.e(this.TAG, "JSONException e = " + e.toString());
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getCleanAreaData(String s1) {
        byte[] decode;
        MyLog.e(this.TAG, "get onReceive data clean_area_info:" + s1);
        try {
            String st = new JSONObject(s1).getString("clean_area");
            if (!TextUtils.isEmpty(st) && (decode = Base64.decode(st, 0)) != null && decode.length > 0) {
                this.whgInfoList.clear();
                ArrayList<ForbiddenInfo> infos = DataUtils.decodeWhfData(decode, true);
                if (infos.size() > 0) {
                    this.whgInfoList.addAll(infos);
                }
                invalidate();
            }
        } catch (JSONException e) {
            MyLog.e(this.TAG, "JSONException e = " + e.toString());
            e.printStackTrace();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getRealTimeMap() {
        ACMsg req = new ACMsg();
        req.setName("searchCleanRealTime");
        req.put("device_id", Long.valueOf(this.deviceId));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, req, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass5 */

            public void success(ACMsg resp) {
                if (resp.getString("slam_map") == null) {
                    MyLog.e(MapView901.this.TAG, "getRealTimeMap success resp.getString(slam_map) is null:");
                    return;
                }
                String strMap = resp.getString("slam_map");
                int xMax = resp.getInt("slam_x_max");
                int xMin = resp.getInt("slam_x_min");
                int yMax = resp.getInt("slam_y_max");
                int yMin = resp.getInt("slam_y_min");
                if (!(xMax - xMin == 0 || yMax - yMin == 0)) {
                    MapView901.this.rectMid.set((float) ((xMax + xMin) / 2), (float) (1500 - ((yMax + yMin) / 2)));
                }
                MyLog.e(MapView901.this.TAG, "test clear map berfor clean-->getRealTimeMap:" + xMax + "," + xMin + "," + yMax + "," + yMin + "<->" + MapView901.this.rectMid.x + "," + MapView901.this.rectMid.y);
                if (!TextUtils.isEmpty(strMap)) {
                    MapView901.this.slamBytes = Base64.decode(strMap, 0);
                    MyLog.e(MapView901.this.TAG, "test clear map berfor clean-->获取到实时地图:" + MapView901.this.slamBytes.length + "," + MapView901.this.isAutoScale + "," + MapView901.this.isFirst);
                    if (MapView901.this.svWidth == 0 && MapView901.this.svHeight == 0) {
                        MapView901.this.svWidth = MapView901.this.getMeasuredWidth();
                        MapView901.this.svHeight = MapView901.this.getMeasuredHeight();
                    }
                    if (MapView901.this.isAutoScale && xMax > 0 && xMin > 0 && yMax > 0 && yMin > 0 && MapView901.this.svWidth > 0 && MapView901.this.svHeight > 0 && MapView901.this.canvas_slam.getWidth() > 0 && MapView901.this.canvas_slam.getHeight() > 0) {
                        MapView901.this.setScale(xMax, xMin, yMax, yMin, MapView901.this.svWidth, MapView901.this.svHeight);
                        if (MapView901.this.isFirst) {
                            MapView901.this.invalidate();
                            MapView901.this.isFirst = false;
                        }
                        MyLog.e(MapView901.this.TAG, "test clear map berfor clean-->实时地图缩放值:" + MapView901.this.curScale + "<->" + MapView901.this.rectMid.x + "," + MapView901.this.rectMid.y + "<->" + MapView901.this.drgx + "," + MapView901.this.drgy);
                    }
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapView901.this.TAG, "getRealTimeMap error " + e.toString());
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void getHistoryRoad() {
        ACMsg reqs = new ACMsg();
        reqs.setName("searchCleanRoadDataMore");
        reqs.put("device_id", Long.valueOf(this.deviceId));
        reqs.put("pageNo", Integer.valueOf(this.pageNo));
        AC.sendToService("", DeviceUtils.getServiceName(this.subdomain), 1, reqs, new PayloadCallback<ACMsg>() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass6 */

            public void success(ACMsg acMsg) {
                int length;
                MyLog.e(MapView901.this.TAG, "test map road data getHistoryRoad==:" + MapView901.this.pageNo + ",");
                ArrayList<ACObject> datas = (ArrayList) acMsg.get("data");
                if (datas != null && datas.size() > 0) {
                    Collections.sort(datas, new OderByTime());
                    Iterator<ACObject> it = datas.iterator();
                    while (it.hasNext()) {
                        byte[] clean_bytes = Base64.decode(it.next().getString("clean_data"), 0);
                        if (clean_bytes != null && (length = clean_bytes.length) > 0) {
                            if (length == 6) {
                                MyLog.e(MapView901.this.TAG, "cleardatas==:" + ((int) clean_bytes[0]) + "," + ((int) clean_bytes[1]) + "," + ((int) clean_bytes[2]) + "," + ((int) clean_bytes[3]) + "," + ((int) clean_bytes[4]) + "," + ((int) clean_bytes[5]));
                            } else if ((length - 2) % 4 == 0) {
                                ArrayList<Integer> roadpoints = new ArrayList<>();
                                for (int j = 2; j < length; j += 4) {
                                    int pointx = DataUtils.bytesToInt(new byte[]{clean_bytes[j], clean_bytes[j + 1]}, 0);
                                    int pointy = DataUtils.bytesToInt(new byte[]{clean_bytes[j + 2], clean_bytes[j + 3]}, 0);
                                    roadpoints.add(Integer.valueOf(((pointx * 224) / 100) + 750));
                                    roadpoints.add(Integer.valueOf(((pointy * 224) / 100) + 750));
                                }
                                MapView901.this.roadPoints.add(roadpoints);
                            }
                        }
                    }
                    if (MapView901.this.isFirsts) {
                        MapView901.this.invalidate();
                    }
                    if (datas.size() == 1000) {
                        MapView901.access$1808(MapView901.this);
                        MapView901.this.getHistoryRoad();
                    }
                }
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
                MyLog.e(MapView901.this.TAG, "getHistoryRoad error==:" + e.toString());
            }
        });
    }

    public void clearMapidSlam() {
        this.mapidBytes = null;
        nameList.clear();
    }

    public void clearRoad() {
        this.packageLists.clear();
        this.roadPoints.clear();
    }

    private void clearRealSlam() {
        this.slamBytes = null;
        this.packageLists.clear();
        this.roadPoints.clear();
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        super.onWindowFocusChanged(hasWindowFocus);
        if (hasWindowFocus) {
            getHistoryRoad();
            upLoadMsg((byte) 1);
            return;
        }
        upLoadMsg((byte) 0);
    }

    /* access modifiers changed from: protected */
    @Override // android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.drgy = 0.0f;
        this.drgy = 0.0f;
        if (this.timer != null) {
            this.timer.cancel();
        }
        this.slamBytes = null;
        this.mapidBytes = null;
    }

    public void upLoadMsg(byte b) {
        sendToDeviceWithOption(new ACDeviceMsg(77, new byte[]{b}), this.physicalDeviceId);
    }

    public void sendToDeviceWithOption(ACDeviceMsg deviceMsg, String physicalDeviceId2) {
        AC.bindMgr().sendToDeviceWithOption(this.subdomain, physicalDeviceId2, deviceMsg, 2, new PayloadCallback<ACDeviceMsg>() {
            /* class com.demostic.demostic_test.ui.MapView901.AnonymousClass7 */

            public void success(ACDeviceMsg acDeviceMsg) {
            }

            @Override // com.accloud.cloudservice.BaseCallback
            public void error(ACException e) {
            }
        });
    }

    public boolean isHaveRoad() {
        if ((this.packageLists == null || this.packageLists.size() <= 0) && (this.roadPoints == null || this.roadPoints.size() <= 0)) {
            return false;
        }
        return true;
    }

    public void setEditData(byte[] slambyte, int xmax, int xmin, int ymax, int ymin) {
        this.mapidBytes = null;
        this.mapidBytes = slambyte;
        this.mapid_xmax = xmax;
        this.mapid_xmin = xmin;
        this.mapid_ymax = ymax;
        this.mapid_ymin = ymin;
        if (slamBytes == null) {
            rectMid.set((float) ((xmax + xmin) / 2), (float) (1500 - ((ymax + ymin) / 2)));
            setScale(xmax, xmin, ymax, ymin, this.width, this.height);
        }
        LogUtil.d("slamBytes->" + Arrays.toString(slamBytes));
        MyLog.e(this.TAG, "test scale map 已保存地图值:" + this.mapid_xmax + "," + this.mapid_xmin + "," + this.mapid_ymax + "," + this.mapid_ymin + "," + this.rectMid.x + "," + this.rectMid.y);
        invalidate();
    }

    public static void setRoomName(HashMap<Integer, RoomNameInfo> nmlist) {
        nameList.clear();
        for (Map.Entry<Integer, RoomNameInfo> entry : nmlist.entrySet()) {
            nameList.put(entry.getKey(), entry.getValue());
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setScale(int xmax, int xmin, int ymax, int ymin, int width2, int height2) {
        int xdistence = xmax - xmin;
        int ydistence = ymax - ymin;
        if (!(xdistence == 0 || ydistence == 0)) {
            this.curScale = (float) ((((double) width2) * 1.0d) / ((double) (xdistence > ydistence ? xdistence : ydistence)));
        }
        if (this.curScale >= this.maxScale) {
            this.curScale = this.maxScale;
        }
        if (this.curScale <= this.minScale) {
            this.curScale = this.minScale;
        }
        this.orgScale = this.curScale;
    }
}
